package org.itboys.mobile.controller.weixin.code;

import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.service.mongo.weixin.code.CooValicodeService;
import org.itboys.mobile.util.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：zzq
 * 时间：2018/2/1
 * 描述：验证码
 */
@Controller
@RequestMapping("/coo/weixin/code")
public class CooWeixinCodeController extends BaseController{
    @Autowired
    private CooValicodeService codeService;

    @RequestMapping("/send")
    public void send(HttpServletRequest request,
                     HttpServletResponse response,
                     @RequestParam(value="mobile",required=true) String mobile){
        try{
            codeService.sendValidateCode(mobile);
            ResponseMessage.success();
        }catch (Exception e){
            e.printStackTrace();
            String msg ="";
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
            }else{
                msg= CommonConstants.ERROMSG;
                logger.error("/coo/weixin/code/send------"+e.getMessage());
            }
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE,e.getMessage()));
        }
    }

}
